package com.Apo1o.service.impl;

import com.Apo1o.entity.bhBasic;
import com.Apo1o.mapper.BhBasicMapper;
import com.Apo1o.service.BhBasicService;
import com.Apo1o.vo.PageResponse;
import com.Apo1o.vo.bhBasicInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Auther: Apo1o.
 * @Date: 2024/5/7-05-07-12:38
 * @Description： com.Apo1o.service.impl
 */
@Service
@RequiredArgsConstructor
public class BhBasicServiceImpl extends ServiceImpl<BhBasicMapper,bhBasic> implements BhBasicService {

    private final BhBasicMapper bhBasicMapper;

    @Override
    public PageResponse<bhBasicInfoVo> getBhBasic(Integer pageNo, Integer pageSize) {
        IPage<bhBasic> bhPage = new Page<>(pageNo, pageSize);



        QueryWrapper<bhBasic> wrapper = new QueryWrapper<>();

        wrapper.orderByDesc("id");


        bhPage = bhBasicMapper.selectPage(bhPage, wrapper);
        List<bhBasicInfoVo> records = bhPage.getRecords().stream().map(bhBasicInfoVo::fromBasic).collect(Collectors.toList());

        return PageResponse.<bhBasicInfoVo>builder().data(records).total(bhPage.getTotal()).build();
    }
}
